﻿@page
@model Emprise.Admin.Pages.NpcScript.AddModel
@{
    ViewData["Title"] = "脚本管理";
    ViewData["MenuGroup"] = MenuGroupEnum.System;
}

@section CssJs{

    <link rel="stylesheet" type="text/css" href="/simditor/styles/simditor.css" />

    <script type="text/javascript" src="/simditor/scripts/jquery.min.js"></script>
    <script type="text/javascript" src="/simditor/scripts/module.js"></script>
    <script type="text/javascript" src="/simditor/scripts/hotkeys.js"></script>
    <script type="text/javascript" src="/simditor/scripts/simditor.js"></script>
    <script type="text/javascript" src="/simditor/scripts/beautify-html.js"></script>
    <script type="text/javascript" src="/simditor/scripts/simditor-html.js"></script>

    <link rel="stylesheet" href="/simditor/styles/simditor-html.css" media="screen" charset="utf-8" />

    <script type="text/javascript" src="/js/template-web.js"></script>
}
<div class="admin-content-body">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">脚本管理</strong> / <small>Script</small></div>
    </div>

    <div class="am-margin">
        <form class="am-form" method="post">
            <div class="am-g">
                <p>@(Model.Tips)</p>
                <div class="am-fade  am-in am-active">
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-2 am-text-right">
                            脚本名
                        </div>
                        <div class="am-u-sm-4">
                            <input type="text" class="am-input-sm" asp-for="NpcScript.Name">
                        </div>
                        <div class="am-u-sm-6"></div>
                    </div>

                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-2 am-text-right">
                            是否入口
                        </div>
                        <div class="am-u-sm-2">
                            <label class="am-btn am-btn-default am-btn-xs">
                                <input type="checkbox" asp-for="NpcScript.IsEntry"> 是否入口
                            </label>

                        </div>
                        <div class="am-u-sm-6">入口将显示在npc资料页面</div>
                    </div>

                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-2 am-text-right">
                            排序
                        </div>
                        <div class="am-u-sm-4">
                            <input type="text" class="am-input-sm" asp-for="NpcScript.SortId" value="99">
                        </div>
                        <div class="am-u-sm-6"></div>
                    </div>


                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-2 am-text-right">
                            分支-如果
                        </div>
                        <div class="am-u-sm-10">
                            <input type="hidden" asp-for="NpcScript.CaseIf">
                            <div class="am-form-inline am-u-sm-10 am-form-group">
                                <select class="am-input-sm am-form-field types">
                                    <option>请选择</option>
                                    @foreach (var item in Enum.GetValues(typeof(ConditionTypeEnum)))
                                    {
                                        <option value="@(item.ToString())">@(item.ToString())</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-4"></div>
                    </div>

                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-2 am-text-right">
                            分支-那么
                        </div>
                        <div class="am-u-sm-10">
                            <input type="hidden" asp-for="NpcScript.CaseThen">
                            <div class="am-form-inline am-u-sm-10 am-form-group">
                                <select class="am-input-sm am-form-field commonds">
                                    <option>请选择</option>
                                    @foreach (var item in Enum.GetValues(typeof(CommondTypeEnum)))
                                    {
                                        <option value="@(item.ToString())">@(item.ToString())</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-4"></div>
                    </div>

                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-2 am-text-right">
                            分支-否则
                        </div>
                        <div class="am-u-sm-10">
                            <input type="hidden" asp-for="NpcScript.CaseElse">
                            <div class="am-form-inline am-u-sm-10 am-form-group">
                                <select class="am-input-sm am-form-field commonds">
                                    <option>请选择</option>
                                    @foreach (var item in Enum.GetValues(typeof(CommondTypeEnum)))
                                    {
                                        <option value="@(item.ToString())">@(item.ToString())</option>
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-4"></div>
                    </div>


                    <div class="am-g am-margin-top-sm">
                        <div class="am-u-sm-2 am-text-right">

                        </div>
                        <div class="am-u-sm-10">
                            <button type="submit" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
                            <a asp-page="/Script/Index" class="am-btn am-btn-default am-btn-xs backup">返回</a>
                            <div class="am-inline-block am-padding-left">
                                <p style="color:#ff0000">@(Model.ErrorMessage)</p>
                                <p style="color:#5FB878">@(Model.SueccessMessage)</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="am-margin">

            </div>
        </form>
    </div>
</div>

<script id="type-角色属性" type="text/html">

    <select class="am-input-sm am-form-field fields attr" attr="Field">
        <option>  请选择  </option>
        {{each fields}}
        <option value="{{$value}}">{{$value}}</option>
        {{/each}}
    </select>

    <select class="am-input-sm am-form-field relations attr" attr="Relation">
        <option>  请选择  </option>
        {{each relations}}
        <option value="{{$value}}">{{$value}}</option>
        {{/each}}
    </select>

    <input type="text" placeholder="数值" class="am-input-sm am-form-field attr"  attr="Value" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" attr="Type" value="保存">
</script>

<script id="type-拥有物品" type="text/html">
    <input type="text" placeholder="物品名" class="am-input-sm am-form-field attr" style="display:inline-block; width:180px;">
    <select class="am-input-sm am-form-field relations attr">
        <option>  请选择  </option>
        {{each relations}}
        <option value="{{$value}}">{{$value}}</option>
        {{/each}}
    </select>

    <input type="text" placeholder="数量" class="am-input-sm am-form-field attr" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>

<script id="type-完成任务" type="text/html">


    <input type="text" placeholder="任务Id" class="am-input-sm am-form-field attr" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>

<script id="type-活动记录" type="text/html">

    <input type="text" class="am-input-sm am-form-field " style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>


<script id="commond-播放对话" type="text/html">


    <input type="text" placeholder="对话内容" class="am-input-sm am-form-field" style="display:inline-block; width:380px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>

<script id="commond-对话选项" type="text/html">

    <input type="text" placeholder="标题" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="text" placeholder="分支id" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>

<script id="commond-输入选项" type="text/html">

    <input type="text" placeholder="提示" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="text" placeholder="分支id" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>

<script id="commond-选择选项" type="text/html">

    <input type="text" placeholder="标题" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="text" placeholder="分支id" class="am-input-sm am-form-field" style="display:inline-block; width:180px;">

    <input type="button" class="am-btn am-btn-default am-btn-xs save" value="保存">
</script>


<script id="data" type="text/html">
    <div class="am-form-inline am-u-sm-10 am-form-group" data="{{$data}}">
        {{$desc}}
    </div>
</script>

@section Scripts {

    <script type="text/javascript">
        var types = @Html.Raw(JsonConvert.SerializeObject(Model.Types));
        var fields = @Html.Raw(JsonConvert.SerializeObject(Model.Fields));
        var relations = @Html.Raw(JsonConvert.SerializeObject(Model.Relations));
        var events = @Html.Raw(JsonConvert.SerializeObject(Model.Events));
        var commonds = @Html.Raw(JsonConvert.SerializeObject(Model.Commonds));

        $(function () {
            $("input[type=checkbox]:checked").each(function () {
                $(this).parent(".am-btn").addClass("am-active");
            });

            $(document).on("change", ".types", function () {
                var type = $(this).val();
                console.log("type=" + type);
                $(this).nextAll("select").remove();
                $(this).nextAll("input").remove();
                var data = { fields: fields, relations: relations };

                if ($("#type-" + type).length>0) {
                    $(this).after(template("type-"+type, data));
                }
            });

            $(document).on("change", ".commonds", function () {
                var type = $(this).val();
                console.log("type=" + type);
                $(this).nextAll("select").remove();
                $(this).nextAll("input").remove();
                var data = { fields: fields, relations: relations };

                if ($("#commond-" + type).length>0) {
                    $(this).after(template("commond-"+type, data));
                }
            });


            $(document).on("click", ".save", function () {
                var type = $(this).attr("attr");
                var obj = {
                    type: type,
                    attrs :[]
                };
                var desc = "";
                var attrs = $(this).parent().find(".attr");
                $.each(attrs, function () {
                    var val = $(this).val(); 
                    var attr = $(this).attr("attr");
                    desc += "   "+val;
                    obj.attrs.push({ attr: attr, val:val });
                });  
                var data = JSON.stringify(obj);
                $(this).parent().prev(template("data", { data: data, desc: desc }));

                $(this).parent().children().not(":first").remove();
            });
        });
    </script>
}
